﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextFlow.Engine
{
    internal class SymbolTable
    {
        private Dictionary<string, Type> _vars = new Dictionary<string, Type>();

        public SymbolTable()
        {
        }

        public void Add( string name, Type t )
        {
            if ( _vars.ContainsKey( name ) )
            {
                if ( _vars[ name ] != t )
                {
                    throw new InvalidOperationException( string.Format( "Cannot change type of variable '{0}'.", name ) );
                }
            }
            else
            {
                _vars.Add( name, t );
            }
        }

        public Type this[ string name ]
        {
            get { return _vars[ name ]; }
        }
    }
}
